<?php

namespace app\models;

use Yii;

/**
 * This is the model class for table "materials".
 *
 * @property integer $id
 * @property string $name
 */
class MaterialModel extends \yii\db\ActiveRecord
{
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'materials';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['name'], 'required'],
            [['name'], 'string', 'max' => 100],
        		[['name'], 'unique'],
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'name' => '物资名称',
        ];
    }
    /**
     * 获取所有物资
     * 
     */
    public function getAllMaterials(){
    	$materials=[];
    	$res=self::find()->asArray()->all();
    	if($res){
    		foreach ($res as $k =>$list){
    			$materials[$list['name']]=$list['name'];
    			
    		}
    	}
    	 
    	return $materials;
    	 
    }
}
